package org.example.carousel.controller;

import org.example.carousel.service.HistoricalSearchService;
import org.example.model.common.Result;
import org.example.model.common.ResultCodeEnum;
import org.example.model.domain.HistoricalSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/historicalsearch")
public class HistoricalSearchController {

    @Autowired
    HistoricalSearchService historicalSearchService;

    @GetMapping("list")
    public Result<HistoricalSearch> list(){
        List<HistoricalSearch> historicalSearches = historicalSearchService.findHistoricalSearch();
        return Result.build(historicalSearches, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("delete")
    public Result<HistoricalSearch> delete(){
        int i = historicalSearchService.deleteHistoricalSearch();
        return Result.build(i, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("add")
    public Result<HistoricalSearch> add(@RequestBody HistoricalSearch historicalSearch){
        int i = historicalSearchService.addHistoricalSearch(historicalSearch);
        return Result.build(i, ResultCodeEnum.SUCCESS);
    }
}
